package cn.itcast.service.impl;


import cn.itcast.dao.MemberStatisticsDao;
import cn.itcast.pojo.PieChart;
import cn.itcast.pojo.Statistics;
import cn.itcast.service.MemberStatisticsService;
import cn.itcast.utils.DateUtils;
import com.alibaba.dubbo.config.annotation.Service;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MemberStatisticsServiceImpl implements MemberStatisticsService {

    @Autowired
   private MemberStatisticsDao memberStatisticsDao;

    /**
     * 折线图功能  查询日期和次数
     * @return
     */
    @Override
    public List<Statistics> selectDateorCount() {
     return memberStatisticsDao.selectDateorCount();
    }

    /**
     * 查询套餐预约统计
     * @return
     */
    @Override
    public List<Map<String, Object>> selectSetMealorCount() {
        return memberStatisticsDao.selectSetMealorCount();
    }
    /**
     * 运营数据统计
     * @return
     * @throws Exception
     */
    @SneakyThrows
    @Override
    public Map<String, Object> findBusiness ()  {
        Map<String, Object> map=new HashMap<>();
        //当前日期
        String today= DateUtils.parseDate2String(DateUtils.getToday());
        map.put("reportDate",today);
        //获取本周一日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月一的日期
        String firstDay4ThisMonth= DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //本日新增会员数
        Integer todayNewMember = this.memberStatisticsDao.findMemberByDate(today);
        //总会员数
        Integer totalMember=this.memberStatisticsDao.findMemberTotal();
        //本周新增会员数eek
        Integer thisWeekNewMember=this.memberStatisticsDao.findMemberCountWeekAfterDate(thisWeekMonday);
        //本月新增会员数
        Integer thisMonthNewMember=this.memberStatisticsDao.findMemberByMonths(firstDay4ThisMonth);

        //今日预约数
        Integer todayOrderNumber=this.memberStatisticsDao.findOrderCountByDate(today);
        //今日到诊数
        Integer todayVisitsNumber=this.memberStatisticsDao.findVisitsCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber=this.memberStatisticsDao.findOrderCountWeekAfterDate(thisWeekMonday);
        //本周到诊数
        Integer thisWeekVisitsNumber= this.memberStatisticsDao.findVisitsCountWeekAfterDate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrderNumber=this.memberStatisticsDao.findOrderCountMonthAfterDate(firstDay4ThisMonth);
        //本月到诊数
        Integer thisMonthVisitsNumber=this.memberStatisticsDao.findVisitsCountMonthAfterDate(firstDay4ThisMonth);


        //热门套餐。预约数据多的 order.setmeal
        List<Map>hotSetmeal=this.memberStatisticsDao.findhotSetmeal();
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }


}
